$(function(){
    router = new Router({
		container: "#container",
		enterTimeout: 250,
		leaveTimeout: 250
	});			
	
	var index = {
		url: "/",
		className: "index",
		render: function () {
			return setTitle("阿宝-赚钱二维码"), template("tpl_empty", {});
		},
		bind: function () {
			$(document).unbind("scroll");
		}
	};
	router.push(index);
	
	var open_value_id = 0;
    var shop = {
		url: "/shop/:id",
		className: "shop",
		render: function () {
			open_value_id = this.params.id;
			return setTitle("开奖宝店"), template("tpl_shop", {});
		},
		bind: function () {			
			$(document).unbind("scroll");
			var _this = this;							
			var urls1 = 'https://market.mofing.com/cloud/video/tagdetail/100625.json?uid=255&token=acc9c2c650688c428f16b93502ea4d82';
			var urls2 = 'https://market.mofing.com/cloud/video/tag/'+ open_value_id +'/zh/0/440300/page:1/limit:100.json?childnote=1&uid=255&token=acc9c2c650688c428f16b93502ea4d82';
			var urls3 = 'http://market.mofing.com/mofingad.json?id=443&city_id=440300&uid=348513&token=b46fdb4964f7dd018dcb62e570eb94ba&';						
			$.get(urls1, {}, function(data){
				if (data.status === 200) {	//标签详情：背景图片				
					var res = data.data;
					$(_this).find('.content').css({						
						'background': 'url('+ res.bgimage_path +') no-repeat',
						'background-position-y': '-2rem',
						'background-size': '100%',
						'background-color': '#'+ res.gbcolor
					});						
				}	
			}).then(				
				$.get(urls2, {}, function(data){
					if (data.status === 200) {	//标签内容：
						var fromId = '';
						for (var i=0;i<data.data.length;i++) {
							if (data.data[i].temp_id === '92124') { //广告temp_id = 92124：															
								if (data.data[i].data_type === '0' || data.data[i].data_type === '4') {
									fromId = 'tid=' + data.data[i].id;
								} else {
									fromId = 'vid=' + data.data[i].id;
								}		
								getAD(fromId);																							
							}
						}																												
						$(_this).find('.hot-classifies').html(template("tpl_hot_classify",data));
					}	
				})				
			);
			ajaxGet('firework/bonus/activity.json', {}, function(data){
				$('.prize_info').html(template('tpl_prize_info_data', data));
			});
			//广告接口
			function getAD(id) {
				$.get(urls3 + id, {}, function(data3){									
					if (data3.status === 200) {
						$(_this).find('.swiper-wrapper').html(template('tpl_ad_swiper', data3));
						var swiper = new Swiper('.swiper-container', {
							initialSlide: 0,//初始位置，如为2则初始为第三个图片
							preventLinksPropagation: true,//阻止click冒泡。拖动Swiper时阻止click事件。				
							loop: false,//true可循环
							autoplay: {
								delay: 5000,//多少毫秒切换一次
							},
							pagination:{
								el: '.swiper-pagination', //分页器容器的css选择器
								clickable: true, //点击分页器的指示点分页器会控制Swiper切换
							},
						});
					}
				});
			}										
		}
	};
	router.push(shop);

    router.setDefault("/").init();
});